package com.jt.controller;

import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController  {
    @Autowired
    private ItemCatService itemCatService;
    @GetMapping("/findItemCatList/{type}")
    public SysResult findItemCatList(@PathVariable Integer type){
        List<ItemCat> catList =itemCatService.findItemCatList(type);
        return SysResult.success(catList);
    }
    /**
     * 需求：实现商品分类状态更新
     * url:/itemCat/status/{id}/{status}
     * 参数：id/status
     * 返回值:SysResult对象
     */
    @PutMapping("/status/{id}/{status}")
    public SysResult updateStatus (ItemCat itemCat){
        itemCatService.updateStatus(itemCat);
        return SysResult.success();
    }

    /**
     * 商品分类新增
     * url：itemCat/saveItemCat
     * 请求参数：整个form表单  JSON
     * 返回值：SysResult
     */
    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat);
        return SysResult.success();
    }

    /**
     *删除商品分类
     * url：itemCat/deleteItemCat
     * 参数：id，level
     * 返回值：SysResult
     */
    @DeleteMapping("/deleteItemCat")
    public SysResult deleteItemCat(Integer id,Integer level){
        itemCatService.deleteItemCat(id,level);
        return SysResult.success();
    }
    @PutMapping("/updateItemCat")
    public SysResult updateItemCat (@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return SysResult.success();
    }
}
